﻿using System;
namespace Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.AnnaIsikuKvalifikatsioonid {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="FyysilineIsik", Namespace="http://producers.etoimik.xtee.riik.ee/producer/etoimik/AnnaIsikuKvalifikatsioonid" +
        "", Target=typeof(FyysilineIsik))]
    public class FyysilineIsikSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IFyysilineIsik clazz;
        
        public FyysilineIsikSerializer(IFyysilineIsik clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("ObjektID");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.ObjektID))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("Kood");
            if (clazz.Kood!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Kood))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Nimi");
            if (clazz.Nimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Nimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Nimi");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("MuudeRiikideKoodid");
            if (clazz.MuudeRiikideKoodid!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.MuudeRiikideKoodid))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Eesnimi");
            if (clazz.Eesnimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Eesnimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Eesnimi");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="ObjektID") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>FyysilineIsik>ObjektID");
                }
                clazz.ObjektID = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("ObjektID")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>FyysilineIsik>ObjektID", Reader.LocalName);
            }
            if (Reader.LocalName=="Kood") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Kood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Kood")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>FyysilineIsik>Kood", Reader.LocalName);
            }
            if (Reader.LocalName=="Nimi") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>FyysilineIsik>Nimi");
                }
                clazz.Nimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Nimi")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>FyysilineIsik>Nimi", Reader.LocalName);
            }
            if (Reader.LocalName=="MuudeRiikideKoodid") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.MuudeRiikideKoodid = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("MuudeRiikideKoodid")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>FyysilineIsik>MuudeRiikideKoodid", Reader.LocalName);
            }
            if (Reader.LocalName=="Eesnimi") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>FyysilineIsik>Eesnimi");
                }
                clazz.Eesnimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Eesnimi")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>FyysilineIsik>Eesnimi", Reader.LocalName);
            }
        }
    }
}
